package com.tomdayu.mybatisdemo;


import com.tomdayu.mybatisdemo.demo1.domain.User;
import com.tomdayu.mybatisdemo.demo1.mapper.UserMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.reflection.ParamNameResolver;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.Reader;
import java.util.List;

public class Test {

    private static SqlSessionFactory sqlSessionFactory;

    public static void main(String[] args) throws IOException {

//        Configuration config = new Configuration();
//        config.setUseActualParamName(true);
//        new ParamNameResolver(config,UserMapper.class.getDeclaredMethods()[1]);

        //1、创建SqlSessionFactory
        String resource = "mybatis-config.xml";
//        String resource = "md";
        final Reader reader = Resources.getResourceAsReader(resource);
        sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
        reader.close();
        //2、获取sqlSession
        SqlSession sqlSession = sqlSessionFactory.openSession();

        //3、获取mapper
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);//动态代理，代理对象

        //4、执行数据库操作，并处理结果集
//        List<User> users = mapper.queryUserBySchoolName2("莉莉");
        List<User> list = mapper.queryUserBySchoolName1(18,"看看","5353",33,"ddd");
//        System.out.println(users.size() + users.get(0).getEmail());

    }
}
